package com.hfi.restful.response;

import com.fasterxml.jackson.annotation.JsonView;
import com.hfi.restful.exception.ErrorCode;
import lombok.Data;

/**
 * @author ChangLiang
 * @date 2019/9/24
 */
@Data
public final class Response<T> extends BaseResponse {

    public interface ResponseView extends BaseResponseView {}

    public interface ResponseDetailView extends Response.ResponseView {}

    /**
     * 返回结果，通常是 Bean 对象对应的 JSON 数据, 通常为了应对不同返回值类型，将其声明为泛型类型
     */
    @JsonView(Response.ResponseView.class)
    private T data;

    public Response() {
    }

    public Response(T data) {
        this.data = data;
    }

    public Response(ErrorCode errorCode, T data) {
        this.setErrorcode(errorCode.value);
        this.setValue(errorCode.memo);
        this.data = data;
    }
}
